package com.longshihan.testart;

import android.os.Bundle;

import com.longshihan.mvplh.base.BaseActivity;
import com.longshihan.mvplh.dagger.component.AppComponent;
import com.longshihan.testart.dagger.component.DaggerActivityComponent;
import com.longshihan.testart.dagger.module.ActivityModule;
import com.longshihan.testart.mvp.model.event.MessageEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class MainActivity extends BaseActivity {
    private AppComponent mAppComponent;

    @Override
    public void onStart() {
        super.onStart();
        EventBus.getDefault().register(this);
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MessageEvent event) {
        /* Do something */
        mAppComponent.appManager().appExit();
    }



    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerActivityComponent.builder()
                .activityModule(new ActivityModule(this))
                .appComponent(appComponent)
                .build()
                .inject(this);
        mAppComponent = appComponent;
    }

    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.activity_main;
    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public boolean useFragment() {
        return false;
    }

    @Override
    public void onStop() {
        super.onStop();
        EventBus.getDefault().unregister(this);
    }
}
